package org.vudroid.core.activities;

import android.content.Context;
import android.text.InputFilter;
import android.text.method.DigitsKeyListener;
import android.view.*;
import android.widget.*;
import org.vudroid.core.DecodeService;
import org.vudroid.core.DocumentView;
import org.vudroid.core.models.CurrentPageModel;
import org.vudroid.core.models.ZoomModel;
import org.vudroid.core.views.PageViewZoomControls;

/**
 * Created by IntelliJ IDEA.
 * User: fabura
 * Date: 22.08.2010
 * Time: 20:12:35
 */
public class ToolBarView extends ViewGroup
{
    private Context context;
    private DocumentView documentView;
    private ZoomModel zoomModel;
    private CurrentPageModel currentPageModel;


    public ToolBarView(final Context context, ZoomModel zoomModel, final DecodeService decodeService, CurrentPageModel currentPageModel)
    {
        super(context);
        this.context = context;
        this.zoomModel = zoomModel;
        this.currentPageModel = currentPageModel;

//        Button button = new Button(context);
//        button.setText("Go to page");
//        button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
//        button.setOnClickListener(new OnClickListener()
//        {
//            public void onClick(View view)
//            {
//                Dialog dialog = new GoToPageDialog(context, documentView, decodeService);
//                dialog.show();
//            }
//        });
//        this.addView(button);
          this.addView(initView());
    }

    private View initView()
    {
        Context mContext = context;
        ViewGroup layout = new LinearLayout(this.getContext());
        layout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        TextView text = new TextView(this.getContext());
        text.setFilters(new InputFilter[]{new DigitsKeyListener(),new InputFilter.LengthFilter(4)});
        text.setText("123");
        layout.addView(text);
//        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
//        View layout = inflater.inflate(R.layout.gotopage,this);
//        GridView numGrid = (GridView)layout.findViewById(R.id.numbersGrid);
//        numGrid.setAdapter(new GoToGridAdapter(getContext()));

        return layout;
    }

    public void setDocumentView(DocumentView documentView)
    {
        this.documentView = documentView;
    }

    private PageViewZoomControls createZoomControls(ZoomModel zoomModel)
    {
        final PageViewZoomControls controls = new PageViewZoomControls(context, zoomModel);
        controls.setGravity(Gravity.RIGHT | Gravity.BOTTOM);
        zoomModel.addEventListener(controls);
        return controls;
    }

    @Override
    protected void onLayout(boolean b, int i, int i1, int i2, int i3)
    {

    }
}
